home *** CD-ROM | disk | FTP | other *** search
/ Java 1996 August / Java - Summer 1996.iso / rockridge / java / threads / betaclasses / CubbyHole.java < prev    next >
Encoding:
Text File  |  1995-11-13  |  397 b   |  22 lines

  1. class CubbyHole {
  2.     private int seq;         // this is the condition variable.
  3.     private boolean available = false;
  4.  
  5.     public synchronized int get() {
  6.     while (available == false) {
  7.         try {
  8.         wait();
  9.         } catch (InterruptedException e) {
  10.         }
  11.     }
  12.     available = false;
  13.     return seq;
  14.     }
  15.  
  16.     public synchronized void put(int value) {
  17.     seq = value;
  18.     available = true;
  19.     notify();
  20.     }
  21. }
  22.